package grandPrize

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/admin-api/pkg/code"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/client/grandprize"
	"github.com/zeromicro/go-zero/core/logc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GrandPrizeInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 详情
func NewGrandPrizeInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GrandPrizeInfoLogic {
	return &GrandPrizeInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GrandPrizeInfoLogic) GrandPrizeInfo(req *types.GrandPrizeInfoReq) (resp *types.GrandPrizeListItemRes, err error) {
	u, err := l.svcCtx.SettingService.GrandPrize.GrandPrizeInfo(l.ctx, &grandprize.GrandPrizeInfoReq{Id: req.Id, MerchantId: 1})

	if err != nil {
		logc.Error(l.ctx, "GrandPrizeInfo err:", err)
		return nil, err
	}

	if u.Code != int64(code.SettingRpcSuccessful.Code()) {
		return nil, code.BusinessFailure
	}

	if u.Data.Id == 0 {
		return nil, code.NotData
	}

	resp = &types.GrandPrizeListItemRes{
		Id:               u.Data.Id,
		MerchantId:       u.Data.MerchantId,
		MultiplierStart:  float64(u.Data.MultiplierStart),
		MultiplierEnd:    float64(u.Data.MultiplierEnd),
		OrderAmountStart: float64(u.Data.OrderAmountStart),
		OrderAmountEnd:   float64(u.Data.OrderAmountEnd),
		Bonus:            float64(u.Data.Bonus),
		Sort:             u.Data.Sort,
		SendDay:          u.Data.SendDay,
		Status:           int64(u.Data.Status),
		Operator:         u.Data.Operator,
		OperatorId:       u.Data.OperatorId,
		CreatedAt:        u.Data.CreatedAt,
		UpdatedAt:        u.Data.UpdatedAt,
	}
	return resp, nil
}
